<?php
$page = 'Video';
$in_site = 'dassnfu';
$loginVereist = 1;
include($_SERVER['DOCUMENT_ROOT']."/start.php");

$bestanden = "<link rel='stylesheet' type='text/css' href='/bestanden/css/style_tabellen".$style_nmr.".css' />
<script type='text/javascript'>
$(document).ready(function() {
	//De rijen van de inlog subnav oplichten als de muis eroverheen gaat
	$('.videobestanden').mouseover(function() {
		$(this).addClass('selected');
	}).mouseout(function() {
		$(this).removeClass('selected');
	});
});
</script>

<style>
.videobestanden p {
	margin: 0px;
	padding: 0px;
}
.videobestanden p a {
	display: block;
	line-height: 2em;
	height: 35px;
}
	

</style>";

include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/database_connectie.php");
include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/dag_maand.php");
include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/instellingen.php");
include_once($_SERVER['DOCUMENT_ROOT']."/header.php");
include_once($_SERVER['DOCUMENT_ROOT']."/sidebar.php");

?>
<div id="main">
<div id="submain">
<div class="content first_child">
<div class="subcontent">
<div class="content_header">
<h1>Video</h1>
</div>
<div class="content_main">
<?php
if(empty($_GET['videoId'])) {
	$result = mysql_query("SELECT DISTINCT Video.videoId, Video.naam, Video.datum, Video.bestand, Team.team FROM Video, Team, Teambeheer
								WHERE Teambeheer.spelerId = '".$_SESSION['spelerId']."' AND Teambeheer.teamId = Video.teamId
									AND Team.teamId = Video.teamId
									AND (Video.datum >= Teambeheer.van
										AND (Video.datum < Teambeheer.tot OR Teambeheer.tot IS NULL))
								ORDER BY Video.datum DESC, Video.naam");
	if($result == null || mysql_num_rows($result) == 0) {
		echo "<div class='error'><p class='icon'>Er zijn geen video's beschikbaar voor de teams waar je gespeeld hebt.</div></p>";
	}else {		
		$color = true;
		$jaar = 0;
		echo "<br>";
		echo "<table class='met_border'>";
			while($row = mysql_fetch_array($result)) {
				if($jaar <> date("Y", strtotime($row['datum']))) {
					$jaar = date("Y", strtotime($row['datum']));
					$color ? $color = false : $color = true;
					echo "<tr class='groot".($color ? " alternate" : "")."'>";
						echo "<td colspan='2' style='width:520px; font-size:20px;'>".$jaar."</td>";
					echo "</tr>";	
				}
				$color ? $color = false : $color = true;
				echo "<tr class='groot videobestanden".($color ? " alternate" : "")."'>";
					echo "<td style='width:120px; height:66px; overflow:hidden;'>";
						echo "<div style='width:120px; height:66px; overflow:hidden;'>";
						echo "<a href='./?videoId=".$row['videoId']."'><img style='position:relative; top:-12px;' src='http://img.youtube.com/vi/".$row['bestand']."/default.jpg' alt='0'></a></div></td>";
					echo "<td class='tabelcel_eerste_kolom' style='width:400px; text-align:left; padding-left:10px; padding-right:10px;'>";
						echo "<p style='float:right; font-style: italic;'>".$row['team']."</p>";
						echo "<p><a href='./?videoId=".$row['videoId']."'>".date("d",strtotime($row['datum']))." ".getMaandString(date("m", strtotime($row['datum'])), false)." ".date("Y", strtotime($row['datum']))."</a></p><p><a href='./?videoId=".$row['videoId']."'>".$row['naam']."</a></p></td>";
				echo "</tr>";
			}
		echo "</table>";
	}
}
else
{
	$result = mysql_query("SELECT Video.videoId, Video.bestand, Video.naam, Video.youtube FROM Video, Teambeheer
								WHERE videoId = '".$_GET['videoId']."'
									AND Teambeheer.spelerId = '".$_SESSION['spelerId']."' AND Teambeheer.teamId = Video.teamId
									AND (Video.datum >= Teambeheer.van
										AND (Video.datum < Teambeheer.tot OR Teambeheer.tot IS NULL))");
	if($result == null || mysql_num_rows($result) == 0) {
		echo "<div class='error'><p class='icon'>Je mag de geselecteerde video niet bekijken of de video bestaat niet.</p></div>";
	}else {
		$row = mysql_fetch_object($result);
		mysql_query("UPDATE Video SET bekeken = bekeken + 1 WHERE videoId = '".$row->videoId."'");

		echo '<script type="text/javascript">'.PHP_EOL;
			echo 'var bestand = '.json_encode($row->bestand).';'.PHP_EOL;
		echo '</script>';
		
		echo "<h3>".$row->naam."</h3>";
		echo "<iframe width='640' height='390' src='http://youtube.com/embed/".$row->bestand."' frameborder='0' allowfullscreen></iframe>";
	}
	echo "<br><br>";
	echo "<a class='button' href='./'><span>Terug</span></a>";
}
echo "</div></div></div></div></div>";	//<!-- content_main --><!-- subcontent --><!-- content --><!-- submain --><!-- main -->
include_once($_SERVER['DOCUMENT_ROOT']."/footer.php");
?>